(1) Field of the Invention
The present invention relates to a data updating apparatus that writes data into a storage medium such as a semiconductor memory, a magnetic disc, and an optical magnetic disc, and especially relates to a technique of restoring consistency after abnormality in data writing causes inconsistency between file management information and the actual storage state of data which constitutes a file.
(2) Prior Art
Information equipment such as a personal computer writes data into a storage medium such as a hard disc, based on a file system. In a file system to write data not into contiguous memory locations in a storage medium but divide the data into pieces (hereinafter called xe2x80x9cdivided pieces of dataxe2x80x9d) and write them into clusters, a FAT (File Allocation Table) and a file index are used. Here, the FAT shows information such as locations of the clusters storing the divided pieces of data and the sequence in which they form a file (hereinafter called xe2x80x9cdata sequencexe2x80x9d). The file index associates a name of the file and a storage location where the top divided piece of data is stored.
The information equipment reads/writes the data from the top divided piece of data to the last divided piece of data in accordance with the FAT and the file index by sequentially tracing the clusters storing the divided pieces of data.
Conventionally, a data updating apparatus is used to update data in the information equipment which employs the file system including the FAT.
FIG. 1 is a functional block diagram showing a conventional data updating apparatus 1000.
The data updating apparatus 1000 is roughly made up of a storage medium 1001, a CPU (Central Processing Unit) 1002, and a RAM (Random Access Memory) 1003, each of which is connected by a bus. The CPU 1002 controls reading/writing of data from/into the storage medium 1001, and the RAM 1003 temporarily stores the data written or read by the CPU 1002.
The storage medium 1001 stores a first FAT 1005, a second FAT 1006 which are obtained by duplexing a FAT, file indexes 1007, 1008, 1009, . . . , and divided pieces of data 1010, 1011, 1012, . . . .
FIG. 2 shows the relationship between the first FAT 1005, the second FAT 1006, the file indexes 1007, 1008, 1009, . . . , and a data storage area 1260.
First, the file indexes 1007, 1008, 1009, . . . , are explained.
File indexes 1007, 1008, 1009, . . . , are tables which are each generated for a file. Since their data structures are the same, the file index 1007 is explained here as an example.
A file name field 1211 shows a filename xe2x80x9cFile1.docxe2x80x9d,; an entry cluster number field 1222 shows a number xe2x80x9c2101xe2x80x9d of a cluster storing the top divided piece of data of the file; a data size field 1223 shows a total data size xe2x80x9c93xe2x80x9d of the file in kilo bytes; an attribute field 1224 shows an attribute xe2x80x9cwritablexe2x80x9d of the file; and a time stamp field 1225 shows xe2x80x9c00/11/02/11:28xe2x80x9d, which is a date and a time when the file index 1007 was generated or updated.
Next, the first FAT 1005 and the second FAT 1006 are explained.
Although usually one FAT is sufficient, the FAT is duplexed to be the first FAT 1005 and the second FAT 1006 for backup in case of abnormality during FAT updating. Since the contents of the first FAT 1005 and the second FAT 1006 are the same, the first FAT 1005 is explained here as an example.
The first FAT 1005 is used for tracing the clusters which store the divided pieces of data in the data sequence.
Each cluster is composed of several sectors, which are the smallest storage units on the storage medium 1001.
A cluster number column 1241 shows a number which specifies a cluster, namely a cluster number.
A pointer column 1242 shows a cluster number of a cluster storing a divided piece of data immediately following a divided piece of data stored in the cluster shown by the cluster number column 1241.
Here, if there is no following divided piece of data, the pointer column 1242 shows an End code which indicates that the following divided piece of data does not exist.
Next, the storage state of the divided pieces of data in the clusters is explained.
A data storage area 1260 is a group of clusters. Each cluster stores one of the divided pieces of data, based on the locations of the clusters and the data sequence indicated by the first FAT 1005 and the second FAT 1006.
That is to say, to obtain data of the file name xe2x80x9cFile1. docxe2x80x9d, the CPU 1002 searches the file indexes 1007, 1008, 1009, . . . for the file name xe2x80x9cFile1.docxe2x80x9d, obtains the file index 1007 which shows the file name xe2x80x9cFile1.docxe2x80x9d, and obtains the entry cluster number xe2x80x9c2101xe2x80x9d.
Next, the CPU 1002 obtains a pointer xe2x80x9c2106xe2x80x9d with reference to the entry cluster number xe2x80x9c2101xe2x80x9d in the first FAT 1005, then obtains a pointer xe2x80x9c2108xe2x80x9d with reference to the cluster number xe2x80x9c2106xe2x80x9d, and finally obtains the End code with reference to the cluster number xe2x80x9c2108xe2x80x9d.
As a result, the CPU 1002 finds out that the data of the file name xe2x80x9cFile1.docxe2x80x9d is made up of the divided pieces of data 1010, 1011, and 1012 that are stored in the clusters with the cluster numbers xe2x80x9c2101xe2x80x9d, xe2x80x9c2106xe2x80x9d, and xe2x80x9c2108xe2x80x9d in sequence. The CPU 1002 then reads the divided pieces of data from the clusters and assembles them, to obtain the data of the file.
When performing file updating by appending or changing data, the CPU 1002 first stores new divided pieces of data necessary for the updating into available clusters, then changes the contents of a corresponding file index such as a data size, updates the cluster numbers and the pointers in the FATs, and deletes divided pieces of data which become unnecessary from clusters.
Here, when updating a file only slightly, not all the divided pieces of data that form the file are subjected to the updating, but only part of them is subjected to the updating in units of clusters.
During such updating, if the updating of one of the FATs is interrupted due to a power failure or the like, the pointer rewriting in the first FAT 1005 or the second FAT 1006 will result in incompletion. This incompletion causes inconsistency with both states of pointers of before and after updating. Even if all of the divided pieces of data are stored in the clusters properly, the CPU 1002 cannot properly recognize their storage locations and sequence, and therefore cannot read the file properly.
To prevent this inconvenience, the CPU 1002 restores to a consistent state in rebooting of the data updating apparatus 1000.
That is to say, when the updating of the first FAT 1005 or the second FAT 1006 is interrupted, the CPU 1002 checks the inconsistency between the first FAT 1005, the second FAT 1006, the file indexes 1007, 1008, 1009, . . . , and the clusters. One of the first FAT 1005 and the second FAT 1006, which has consistency, is used as a proper FAT, and the other is changed so as to be the same as the proper FAT. This processing restores to a consistent state.
As for the file indexes, since the data size of each index is small enough to store in one sector, it is not assumed here that the updating of any of the file indexes 1007, 1008, 1009, . . . , is interrupted.
In recent years, a variety of digital information household electrical appliances such as digital televisions and game machines, which receive information such as video, audio, and data and write it into a storage medium such as a hard disc.
These digital information household electrical appliances are equipped with data updating apparatuses similar to those in personal computers.
The above conventional restoration processing has the following problem.
The conventional restoration processing takes a long time to check the inconsistency between the first FAT 1005, the second FAT 1006, the file indexes 1007, 1008, 1009, . . . , and the clusters. Accordingly, the data updating apparatus takes a long time until it resumes to read/write data.
Therefore, especially users of digital information household electrical appliances such as the digital televisions and the game machines that are based on real time processing are likely to be irritated.
The present invention is led in consideration of the above problem, and the first object of the present invention is to provide a data updating apparatus that can shorten the restoration processing time.
Also, the second object of the present invention is to provide a data updating method that can perform the above improved restoration processing.
Furthermore, the third object of the present invention is to provide a storage medium storing a program that shortens the restoration processing time.
The first object is achieved by a data updating apparatus for updating a file in a storage medium which stores: (a) one or more files including the file to be updated, each of which includes a plurality of pieces of data, (b) a first table and a second table which both indicate a storage location of each piece of data and a sequence of the plurality of pieces of data of each file, and (c) one or more pieces of index information which are in a one-to-one correspondence with the one or more files and each associate a file name with a storage location of a predetermined piece of data of a file, the data updating apparatus including: a unit for updating the first table, a piece of index information corresponding to the file to be updated, and the second table in the stated order in updating of the file; a unit for generating and writing index identifying information into the storage medium before the first table is updated, the index identifying information including (i) address information which shows a storage location of the corresponding piece of index information and (ii) new contents to which the corresponding piece of index information is to be updated; and a unit for deleting the index identifying information from the storage medium after the second table is updated.
With this construction, if restoration processing is to be performed when the index identifying information exists in the storage medium after the file updating results in incompletion, the need of restoration processing can be easily judged by judging whether the index identifying information exists or not. Accordingly, restoration processing can be started soon.
The data updating apparatus further includes: a unit for judging whether the index identifying information exists in the storage medium after the updating of the file results in incompletion; and a unit for, when the index identifying information exists, restoring consistency by (a) reading the corresponding piece of index information specified by the address information, (b) comparing contents of the corresponding piece of index information with the new contents of the corresponding piece of index information included in the index identifying information, and (c) restoring consistency by (i) changing the second table so as to have same contents as the first table when the contents of the corresponding piece of index information match the new contents of the corresponding piece of index information, and (ii) changing the first table so as to have same contents as the second table when the contents of the corresponding piece of index information are different from the new contents of the corresponding piece of index information.
With this construction, the need of the restoration processing can be easily judged by judging whether the index identifying information exists or not. The data updating apparatus then obtains the corresponding piece of index information, based on the address information, and changes one of the first table and the second table so as to have the same contents as the other in accordance with the result of comparing the contents of the corresponding piece of index information with the new contents of the corresponding piece of index information included in the index identifying information. Consequently, without comparing these tables with the storage state of the plurality of pieces of data, the restoration processing of the first table and the second table is performed. As a result, a restoration processing time is shortened.
In the data updating apparatus, the index identifying information generating/writing unit sets a predetermined bit in the storage medium to a first value when writing the index identifying information, the index identifying information deleting unit sets the predetermined bit to a second value which is different from the first value when deleting the index identifying information, and the judging unit performs the judging, based on the predetermined bit.
With this construction, the need of restoration processing can be easily judged only by referring to the value in the predetermined bit.
Also, in the data updating apparatus, the restoring unit deletes the index identifying information from the storage medium and sets the predetermined bit to the second value after completing the restoring.
With this construction, in the second or later restoration processing, the need of restoration processing can be easily judged only by referring to the value in the predetermined bit.
In the data updating apparatus, the restoring unit deletes the index identifying information from the storage medium after completing the restoring.
With this construction, in the second or later restoration processing, the need of restoration processing can be easily judged by judging whether the index identifying information exists or not.
The second object is achieved by a data updating method for updating a file in a storage medium which stores: (a) one or more files including the file to be updated, each of which includes a plurality of pieces of data, (b) a first table and a second table which both indicate a storage location of each piece of data and a sequence of the plurality of pieces of data of each file, and (c) one or more pieces of index information which are in a one-to-one correspondence with the one or more files and each associate a file name with a storage location of a predetermined piece of data of a file, the data updating method including the steps of: updating the first table, a piece of index information corresponding to the file to be updated, and the second table in the stated order in updating of the file; generating and writing index identifying information into the storage medium before the first table is updated, the index identifying information including (i) address information which shows a storage location of the corresponding piece of index information and (ii) new contents to which the corresponding piece of index information is to be updated; and deleting the index identifying information from the storage medium after the second table is updated.
With this construction, if restoration processing is to be performed when the index identifying information exists in the storage medium after the file updating results in incompletion, the need of restoration processing can be easily judged by judging whether the index identifying information exists or not. Accordingly, restoration processing can be started soon.
The data updating method further includes the steps of: judging whether the index identifying information exists in the storage medium after the updating of the file results in incompletion; and restoring consistency by, when the index identifying information exists, (a) reading the corresponding piece of index information specified by the address information, (b) comparing contents of the corresponding piece of index information with the new contents of the corresponding piece of index information included in the index identifying information, and (c) restoring consistency by (i) changing the second table so as to have same contents as the first table when the contents of the corresponding piece of index information match the new contents of the corresponding piece of index information, and (ii) changing the first table so as to have same contents as the second table when the contents of the corresponding piece of index information are different from the new contents of the corresponding piece of index information.
With this construction, the need of the restoration processing can be easily judged by judging whether the index identifying information exists or not. The data updating apparatus then obtains the corresponding piece of index information, based on the address information, and changes one of the first table and the second table so as to have the same contents as the other in accordance with the result of comparing the contents of the corresponding piece of index information with the new contents of the corresponding piece of index information included in the index identifying information. Consequently, without comparing these tables with the storage state of the plurality of pieces of data, the restoration processing of the first table and the second table is performed. As a result, a restoration processing time is shortened.
The third object is achieved by a computer-readable storage medium that stores a data updating program to update a file in a storage medium which stores: (a) one or more files including the file to be updated, each of which includes a plurality of pieces of data, (b) a first table and a second table which both indicate a storage location of each piece of data and a sequence of the plurality of pieces of data of each file, and (c) one or more pieces of index information which are in a one-to-one correspondence with the one or more files and each associate a file name with a storage location of a predetermined piece of data of a file, the data updating program including the steps of: updating the first table, a piece of index information corresponding to the file to be updated, and the second table in the stated order in updating of the file; generating and writing index identifying information into the storage medium before the first table is updated, the index identifying information including (i) address information which shows a storage location of the corresponding piece of index information and (ii) new contents to which the corresponding piece of index information is to be updated; and deleting the index identifying information from the storage medium after the second table is updated.
With this construction, if restoration processing is to be performed when the index identifying information exists in the storage medium after the file updating results in incompletion, the need of restoration processing can be easily judged by judging whether the index identifying information exists or not. Accordingly, restoration processing can be started soon.